package com.kaibes.module.logger;

import java.math.BigInteger;
import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kaibes.core.base.annotation.Description;
import com.kaibes.orm.core.core.Page;
import com.kaibes.web.api.ApiLink;
import com.kaibes.web.api.ResponseApi;
import com.kaibes.web.response.ResponseFactory;

@RestController
@RequestMapping("/logs")
public class ApiLogApi extends ResponseApi<ApiLog, ApiLogService> {

	@PostMapping
	public ResponseEntity<List<BigInteger>> post(@RequestBody ApiLog apiLog) {
		return super.post(apiLog, "保存请求日志成功", "保存请求日志失败");
	}
	
	@GetMapping("/page")
	@ApiLink("获取日志分页")
	public ResponseEntity<Page<ApiLog>> get(
			@RequestParam(defaultValue = "25") @Description("每页长度") int size,
            @RequestParam(defaultValue = "1") @Description("当前页数") int current, 
            @RequestParam(defaultValue = "") @Description("搜索内容") String search) {
		return ResponseFactory.get(service.page(size, current, search), "获取数据成功", "获取数据失败");
	}
	
}
